# -*- coding: utf-8 -*-
import os
import argparse
import codecs
import json
from flask import Flask, request, jsonify


parser = argparse.ArgumentParser(
    description='ID.MI Labels - 20250331'
)
parser.add_argument('--PORT',
                    type=int,
                    help='PORT',
                    default=int(os.getenv('PORT', '17400')),
                    required=False)
parser.add_argument('--DEBUG_MODE',
                    type=bool,
                    help='DEBUG_MODE',
                    default=True,
                    required=False)
args = parser.parse_args()

app = Flask(__name__)



@app.after_request
def set_response_headers(response):
    response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
    response.headers['Pragma'] = 'no-cache'
    response.headers['Expires'] = '0'
    return response


"""
feeling labels
"""
@app.route('/feeling_labels_zh', methods=['GET'])
def feeling_labels_zh():
    with codecs.open(filename='labels/cuzu_labels_20250331.json',
                     mode='r',
                     encoding='utf-8') as fr:
        feeling_labels = json.load(fr)
    return json.dumps(feeling_labels, ensure_ascii=False)


# @app.route('/feeling_labels_convert', methods=['GET'])
# def feeling_labels_en():
#     with codecs.open(filename='labels/cuzu_labels_trans_20250212.json', mode='r',
#                      encoding='utf-8') as fr:
#         feeling_labels = json.load(fr)
#     return json.dumps(feeling_labels, ensure_ascii=False)
#

"""
forum labels
"""
@app.route('/forum_labels_zh', methods=['GET'])
def forum_labels_zh():
    with codecs.open(filename='labels/forum_labels_20250212.json', mode='r',
                     encoding='utf-8') as fr:
        forum_labels = json.load(fr)
    return json.dumps(forum_labels, ensure_ascii=False)

"""
purchasing labels
"""
@app.route('/purchasing_labels_zh', methods=['GET'])
def purchasing_labels_zh():
    with codecs.open(filename='labels/purchasing_labels_20250212.json', mode='r',
                     encoding='utf-8') as fr:
        purchasing_labels = json.load(fr)
    return json.dumps(purchasing_labels, ensure_ascii=False)

"""
sentiment labels
"""
@app.route('/sentiment_labels_zh', methods=['GET'])
def sentiment_labels_zh():
    with codecs.open(filename='labels/sentiment_labels_20250212.json', mode='r',
                     encoding='utf-8') as fr:
        sentiment_labels = json.load(fr)
    return json.dumps(sentiment_labels, ensure_ascii=False)



if __name__ == '__main__':
    app.run(host='0.0.0.0',
            port=args.PORT,
            debug=True)








"""

quality_labels

with codecs.open(filename='labels/Quality_labels_trans_20250212.json', mode='r',
                 encoding='utf-8') as fr:
    quality_labels = json.load(fr)

@app.route('/quality_labels_zh', methods=['GET'])
def quality_labels_zh():
    quality_label_dict = {}
    for label in list(quality_labels.keys()):
        K, V = label.split('@@')
        if K not in quality_label_dict.keys():
            quality_label_dict.update({K: []})
        quality_label_dict[K].append(V)
    return json.dumps(quality_label_dict, ensure_ascii=False)

@app.route('/quality_labels_en', methods=['GET'])
def quality_labels_en():
    quality_label_dict = {}
    for label in list(quality_labels.values()):
        K, V = label[0].split('@@')
        if K not in quality_label_dict.keys():
            quality_label_dict.update({K: []})
        quality_label_dict[K].append(V)
    return json.dumps(quality_label_dict, ensure_ascii=False)

@app.route('/quality_label_zh2en', methods=['GET'])
def quality_labels_translate():
    quality_label_dict = {}
    for key, value in quality_labels.items():
        quality_label_dict.update({key : value[0]})
    return quality_label_dict


csp_labels

@app.route('/csp_labels_zh', methods=['GET'])
def csp_labels_zh():
    with codecs.open(filename='labels/csp_labels_20250212.json', mode='r',
                     encoding='utf-8') as fr:
        csp_labels = json.load(fr)
    return json.dumps(csp_labels, ensure_ascii=False)

@app.route('/csp_labels_convert', methods=['GET'])
def csp_labels_en():
    with codecs.open(filename='labels/csp_labels_en_20250212.json', mode='r',
                     encoding='utf-8') as fr:
        csp_labels_en = json.load(fr)
    return json.dumps(csp_labels_en, ensure_ascii=False)


"""


